package org.cnc.explain.lifecycle.hookbean;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.*;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.util.ReaderHelper;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;

/**
 * <p>
 * #TODO: desc
 * </p>
 *
 * @author zhiyong.tan
 * @since 2022-09-14
 */

public class HookBean implements InitializingBean, DisposableBean , BeanNameAware, BeanClassLoaderAware, BeanFactoryAware , ApplicationContextAware {

	public void customInitMethod(){
		PrintHelper.printMsgWithStep("执行 自定义初始化方法 回调");
	}

	public void customDestroy(){
		PrintHelper.printMsgWithStep("执行 自定义销毁方法 回调");
	}

	@Override
	public void destroy() throws Exception {
		PrintHelper.printMsgWithStep("执行  DisposableBean#destroy 回调");
	}

	@Override
	public void afterPropertiesSet() throws Exception {
		PrintHelper.printMsgWithStep("执行  InitializingBean#afterPropertiesSet 回调");
	}

	@PreDestroy
	public void preDestroy(){
		PrintHelper.printMsgWithStep("执行  @PreDestroy 回调");

		ReaderHelper.formatTrace();
	}

	@PostConstruct
	public void postConstruct(){
		PrintHelper.printMsgWithStep("执行  @PostConstruct 回调");
		ReaderHelper.formatTrace();
	}

	@Override
	public void setBeanName(String name) {
		PrintHelper.printMsgWithStep("执行  BeanNameAware#setBeanName 回调");
	}

	@Override
	public void setBeanClassLoader(ClassLoader classLoader) {
		PrintHelper.printMsgWithStep("执行  BeanClassLoaderAware#setBeanClassLoader 回调");
	}

	@Override
	public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
		PrintHelper.printMsgWithStep("执行  BeanFactoryAware#beanFactory 回调");
	}

	@Override
	public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
		PrintHelper.printMsgWithStep("执行  ApplicationContextAware#setApplicationContext 回调");
	}
}

